package com.base.helper;

import com.base.utils.Md5Encrypt;
import com.base.utils.Produce;
import net.sf.json.JSONObject;

public class LJSmsHelper {

	/**
	 * 上海聆界短信
	 * 
	 * @param mobile  手机号码
	 * @param parentName 代理商
	 * @param num 验证码
	 * @return
	 */
	public static String sendSms( String mobile, String parentName, Integer num) {
		Integer time = Math.round(Produce.getNowDate().getTime()/1000);

		String sign = null; // MD5加密
		try {
			sign = Md5Encrypt.encrypt32("userCode=suibiandayzm&timestamp=" + time + "34gK3Udt");
		} catch (Exception e) {
			e.printStackTrace();
		}
		String url = "http://www.lisglo.com/smssend/send?userCode=suibiandayzm&timestamp="+time +"&sign=" + sign;

		JSONObject postData = new JSONObject();
		postData.put("phoneNumber", mobile);
		postData.put("sign", "【"+ parentName +"】");
		postData.put("content", "尊敬的用户您好:您本次验证码为:" + num + ",如非本人操作,请忽略本短信");

//		String postData = "{\"phoneNumber\":\""+ mobile +"\",\"sign\":\"【"+ parentName.trim() +"】\",\"content\":\"尊敬的用户您好:您本次验证码为:"+ num +",如非本人操作,请忽略本短信\",\"returnStatusUrl\":\"http://www.lisglo.com/smssend/send\",\"returnUpUrl\":\"http://www.lisglo.com/smssend/send\"}";

		String json = null;
		try {
			json = WebHelper.PostData(url, postData.toString(),"application/json;charset=UTF-8", null);
			System.out.println(json);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return json;
	}

	public static String sendShopSms(String mobile, String parentName, String userName, String userMobile, String orderNo) {
		Integer time = Math.round(Produce.getNowDate().getTime()/1000);

		String sign = null; // MD5加密
		try {
			sign = Md5Encrypt.encrypt32("userCode=suibiandayzm&timestamp=" + time + "34gK3Udt");
		} catch (Exception e) {
			e.printStackTrace();
		}
		String url = "http://www.lisglo.com/smssend/send?userCode=suibiandayzm&timestamp="+time +"&sign=" + sign;

		JSONObject postData = new JSONObject();
		postData.put("phoneNumber", mobile);
		postData.put("sign", "【"+ parentName +"】");
		postData.put("content", "您好，用户" + userName + "(" + userMobile + ")" + "购买了商品，您的商城有新订单(" + orderNo + ")，请尽快处理");

		String json = null;
		try {
			json = WebHelper.PostData(url, postData.toString(),"application/json;charset=UTF-8", null);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return json;
	}

	/**
	 * 上海聆界短信
	 *
	 * @param mobile  手机号码
	 * @param parentName 代理商
	 * @param String msg 提示
	 * @return
	 */
	public static String sendSmsToGasPay( String mobile, String parentName, String msg) {
		Integer time = Math.round(Produce.getNowDate().getTime()/1000);

		String sign = null; // MD5加密
		try {
			sign = Md5Encrypt.encrypt32("userCode=suibiandayzm&timestamp=" + time + "34gK3Udt");
		} catch (Exception e) {
			e.printStackTrace();
		}
		String url = "http://www.lisglo.com/smssend/send?userCode=suibiandayzm&timestamp="+time +"&sign=" + sign;

		JSONObject postData = new JSONObject();
		postData.put("phoneNumber", mobile);
		postData.put("sign", "【"+ parentName +"】");
		postData.put("content", "尊敬的用户您好: "+msg);


		String json = null;
		try {
			json = WebHelper.PostData(url, postData.toString(),"application/json;charset=UTF-8", null);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return json;
	}
}